package club.framework.web.application.sys.user.entity;



import club.framework.web.base.common.Constants;
import club.framework.web.base.common.Crypto;
import club.framework.web.base.entity.BaseEntity;
import club.framework.web.base.util.DateFormatUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * Created by 念梓  on 2017/6/8.
 * Email:sunmch@163.com
 * author: 念梓
 * des:
 */
public class User extends BaseEntity {

    private String username;

    private String password;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday;

    private String sex="女";  //

    private String deptCode;

    private String deptName;

    private String mobile;

    private String phone;  //办公室电话号码

    private String position;  //职位

    private String type;  //用户类型

    private String flag="0";  //状态 0：正常  1：禁用

    private String birthdayStr;

    private String roleIds;

    private String decryptPassword;


    public String getUsername() {
            return  username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
       return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getDeptCode() {
        return deptCode;
    }

    public void setDeptCode(String deptCode) {
        this.deptCode = deptCode;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    public String getBirthdayStr() {
        return DateFormatUtils.getFormatDate(this.getBirthday(),"yyyy-MM-dd");
    }

    public void setBirthdayStr(String birthdayStr) {
        this.birthdayStr = birthdayStr;
    }


    public String getRoleIds() {
        return roleIds;
    }

    public void setRoleIds(String roleIds) {
        this.roleIds = roleIds;
    }

    public String getDecryptPassword() throws Exception {
        return Crypto.getInstance().decrypt(this.getPassword(),Constants.DB_USERINFO_ENCRYPT_KEY);
    }

    public void setDecryptPassword(String decryptPassword) {
        this.decryptPassword = decryptPassword;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("User{");
        sb.append("username='").append(username).append('\'');
        sb.append(", password='").append(password).append('\'');
        sb.append(", birthday=").append(birthday);
        sb.append(", sex='").append(sex).append('\'');
        sb.append(", deptCode='").append(deptCode).append('\'');
        sb.append(", deptName='").append(deptName).append('\'');
        sb.append(", mobile='").append(mobile).append('\'');
        sb.append(", phone='").append(phone).append('\'');
        sb.append(", position='").append(position).append('\'');
        sb.append(", type='").append(type).append('\'');
        sb.append(", flag='").append(flag).append('\'');
        sb.append(", birthdayStr='").append(birthdayStr).append('\'');
        sb.append(", roleIds='").append(roleIds).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
